/**
 * 自动化工具生成 version 1.0 
 * @author Jason.Wang
 * @blog http://kzone.iteye.com
 * @email kzone.wang@msn.com
 */
package org.kzone.jason.mybatis.utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import javax.persistence.Column;
import javax.persistence.Table;

import org.apache.log4j.Logger;
import org.kzone.jason.utils.config.Configs;

/**
 *<pre>
 * <b>Company</b> <title>© 购物中国</title>(<a href="http://www.gouwcn.com" title="购物中国">http://www.gouwcn.com</a>) 
 * <b>Date</b> 2012-03-19 11:40:03
 * <b>Author</b> Jason.Wang
 * <b>Project</b> http://www.gouwcn.com
 * <b>Description</b> 用于根据JPA生成的Entity生成对应的Mybatis3.0.1的Mapper(*.xml,*.java)、Service接口、ServerImpl等
 * <b>Version</b> 1.0
 *</pre>
 */
public class CreateMapper {
	private final static Logger logger = Logger.getLogger(CreateMapper.class);
	//原包的package的路径
	private static String nameSpace = "org.kzone.jason.entity";
	private static String sourceDir = nameSpace.replaceAll("\\.", "/");
	//生成的Mapper存放的地址
	private static String targetSpace = "org.kzone.jason.mapper";
	private static String targetDir = targetSpace.replaceAll("\\.", "/");
	private static String targetoutFileDir = ClassLoader.getSystemResource("").getPath()+targetDir;
	
	private static String serviceSpace = "org.kzone.jason.service";
	private static String serviceDir = serviceSpace.replaceAll("\\.", "/");
	private static String serviceOutFileDir = ClassLoader.getSystemResource("").getPath()+serviceDir;
	
	private static String serviceImplSpace = "org.kzone.jason.service.impl";
	private static String serviceImplDir = serviceImplSpace.replaceAll("\\.", "/");
	private static String serviceImplOutFileDir = ClassLoader.getSystemResource("").getPath()+serviceImplDir;
	
	private static String companyName = "<title>© 购物中国</title>(<a href=\"http://www.gouwcn.com\" title=\"购物中国\">http://www.gouwcn.com</a>)";
	private static String projectName = "http://www.gouwcn.com";
	private static String file_author = "Jason.Wang";
	
	static{
		//原包的package的路径
		nameSpace = Configs.getInstance().getProperty("nameSpace");
		targetSpace = Configs.getInstance().getProperty("targetSpace");
		serviceSpace = Configs.getInstance().getProperty("serviceSpace");
		serviceImplSpace = Configs.getInstance().getProperty("serviceImplSpace");
		companyName = Configs.getInstance().getProperty("companyName");
		projectName = Configs.getInstance().getProperty("projectName");
		file_author = Configs.getInstance().getProperty("file_author");
		
		nameSpace = null != nameSpace ? nameSpace : "org.kzone.jason.entity";
		targetSpace = null != targetSpace ? targetSpace : "org.kzone.jason.mapper";
		serviceSpace = null != serviceSpace ? serviceSpace : "org.kzone.jason.service";
		serviceImplSpace = null != serviceImplSpace ? serviceImplSpace : "org.kzone.jason.service.impl";
		companyName = null != companyName ? companyName : "<title>© 购物中国</title>(<a href=\"http://www.gouwcn.com\" title=\"购物中国\">http://www.gouwcn.com</a>)";
		projectName = null != projectName ? projectName : "http://www.gouwcn.com";
		file_author = null != file_author ? file_author : "Jason.Wang";
		
		sourceDir = nameSpace.replaceAll("\\.", "/");
		targetDir = targetSpace.replaceAll("\\.", "/");
		targetoutFileDir = ClassLoader.getSystemResource("").getPath()+targetDir;
		serviceDir = serviceSpace.replaceAll("\\.", "/");
		serviceOutFileDir = ClassLoader.getSystemResource("").getPath()+serviceDir;
		serviceImplDir = serviceImplSpace.replaceAll("\\.", "/");
		serviceImplOutFileDir = ClassLoader.getSystemResource("").getPath()+serviceImplDir;
	}
	
	private static CreateMapper createMapper = null;
	
	public static CreateMapper getInstance(){
		if(null==createMapper){
			createMapper = new CreateMapper();
		}
		return createMapper;
	}
	
	public static void main(String[] args) {
		CreateMapper.getInstance().createMapperXml();
	}
	
	public void createMapperXml() {
		//获取Entity(POJO)实体对象的存放路径
		String path = ClassLoader.getSystemResource("").getPath()+ sourceDir;
		File file = new File(path);
		if(file.exists() && file.isDirectory()){
			//获取当前文件夹下面的所有文件数组
			String[] fileArr = file.list();
			
			//清空文件夹中的多余的文件
			File outDir = new File(targetoutFileDir);
			if(!outDir.exists()){
				outDir.mkdirs();
			}else{
				if(outDir.isDirectory()){
					delFolder(outDir.getPath());
				}else{
					outDir.delete();
				}
				outDir.mkdirs();
			}
			
			File serviceOutDir = new File(serviceOutFileDir);
			if(!serviceOutDir.exists()){
				serviceOutDir.mkdirs();
			}else{
				if(outDir.isDirectory()){
					delFolder(serviceOutDir.getPath());
				}else{
					serviceOutDir.delete();
				}
				serviceOutDir.mkdirs();
			}
			
			File serviceImplOutDir = new File(serviceImplOutFileDir);
			if(!serviceImplOutDir.exists()){
				serviceImplOutDir.mkdirs();
			}else{
				serviceImplOutDir.delete();
				serviceImplOutDir.mkdirs();
			}
			for (String fileName : fileArr) {
				if(-1!=fileName.indexOf(".class")){
					try{
						String className = fileName.replaceAll(".class", "");
						
						//获取当前类的所有的字段
						Field[] fields = getFieldsOfClass(nameSpace + "." + className);
						//获取当前类上的所有的注解，用来获取当前类对应的数据库的表的名称
						Annotation[] tannotations = getAnnotationsOfClass(nameSpace + "." + className);
						String tableName = getTableNameOfClassByAnnotations(tannotations);
						
						if(1 > tannotations.length){
							System.err.println(className);
							continue;
						}
						
						//生产一个输出对象。
						File outFile = new File(outDir.getPath()+File.separator+className+"Mapper.xml");
						File ioutFile = new File(outDir.getPath()+File.separator+className+"Mapper.java");
						File iserviceOutFile = new File(serviceOutDir.getPath()+File.separator+"I"+className+"Service.java");
						File serviceImplOutFile = new File(serviceImplOutDir.getPath()+File.separator+className+"ServiceImpl.java");
						OutputStreamWriter outputWriter = new OutputStreamWriter(new FileOutputStream(outFile),"UTF-8");
						OutputStreamWriter ioutputWriter = new OutputStreamWriter(new FileOutputStream(ioutFile),"UTF-8");
						OutputStreamWriter iserviceOutputWriter = new OutputStreamWriter(new FileOutputStream(iserviceOutFile),"UTF-8");
						OutputStreamWriter serviceImplOutputWriter = new OutputStreamWriter(new FileOutputStream(serviceImplOutFile),"UTF-8");
						
						
						//生成的文件的头部
						ioutputWriter.write("/**\n");
						ioutputWriter.write(" * 使用自动化工具生成 version 1.0 \n");
						ioutputWriter.write(" * @author Jason.Wang\n");
						ioutputWriter.write(" * @blog http://kzone.iteye.com\n");
						ioutputWriter.write(" * @email kzone.wang@msn.com\n");
						ioutputWriter.write(" */\n");
						
						ioutputWriter.write("package "+ targetSpace +";\n");
						ioutputWriter.write("import java.io.Serializable;\n\n");
						ioutputWriter.write("import java.util.*;\n\n");
						ioutputWriter.write("import org.apache.ibatis.session.RowBounds;\n\n");
						ioutputWriter.write("import "+ nameSpace +".*;\n\n");
						
						ioutputWriter.write("/**\n");
						ioutputWriter.write(" *<pre>\n");
						ioutputWriter.write(" * <b>Company</b> "+ companyName +" \n");
						//ioutputWriter.write(" * <b>Date</b> "+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) +"\n");
						ioutputWriter.write(" * <b>Author</b> " + file_author +"\n");
						ioutputWriter.write(" * <b>Project</b> "+ projectName +"\n");
						ioutputWriter.write(" * <b>Description</b> 用于MyBatis数据库操作的 "+className+"Mapper类 \n");
						ioutputWriter.write(" * <b>Version</b> 1.0\n");
						ioutputWriter.write(" *</pre>\n");
						ioutputWriter.write(" */\n");
						
						ioutputWriter.write("public interface "+className+"Mapper extends Serializable{\n");
						
						//生成自定业务逻辑的代码
						iserviceOutputWriter.write("/**\n");
						iserviceOutputWriter.write(" * 使用自动化工具生成 version 1.0 \n");
						iserviceOutputWriter.write(" * @author Jason.Wang\n");
						iserviceOutputWriter.write(" * @blog http://kzone.iteye.com\n");
						iserviceOutputWriter.write(" * @email kzone.wang@msn.com\n");
						iserviceOutputWriter.write(" */\n");
						
						iserviceOutputWriter.write("package "+ serviceSpace +";\n");
						//iserviceOutputWriter.write("import java.io.Serializable;\n\n");
						iserviceOutputWriter.write("import java.util.*;\n\n");
						iserviceOutputWriter.write("import "+ nameSpace +"."+className+";\n\n");
						
						iserviceOutputWriter.write("/**\n");
						iserviceOutputWriter.write(" *<pre>\n");
						iserviceOutputWriter.write(" * <b>Company</b> "+ companyName +" \n");
						//iserviceOutputWriter.write(" * <b>Date</b> "+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) +"\n");
						iserviceOutputWriter.write(" * <b>Author</b> " + file_author +"\n");
						iserviceOutputWriter.write(" * <b>Project</b> "+ projectName +"\n");
						iserviceOutputWriter.write(" * <b>Description</b> 用于"+className+"类的业务操作类 "+className+"ServiceImpl的接口 \n");
						iserviceOutputWriter.write(" * <b>Version</b> 1.0\n");
						iserviceOutputWriter.write(" *</pre>\n");
						iserviceOutputWriter.write(" */\n");
						
						iserviceOutputWriter.write("public interface I"+className+"Service extends Serializable{\n");
						
						
						//实现类
						serviceImplOutputWriter.write("/**\n");
						serviceImplOutputWriter.write(" * 使用自动化工具生成 version 1.0 \n");
						serviceImplOutputWriter.write(" * @author Jason.Wang\n");
						serviceImplOutputWriter.write(" * @blog http://kzone.iteye.com\n");
						serviceImplOutputWriter.write(" * @email kzone.wang@msn.com\n");
						serviceImplOutputWriter.write(" */\n");
						
						serviceImplOutputWriter.write("package "+ serviceImplSpace +";\n\n");
						serviceImplOutputWriter.write("import javax.annotation.Resource;\n");
						//serviceImplOutputWriter.write("import java.io.Serializable;\n");
						serviceImplOutputWriter.write("import "+ serviceSpace + ".I" + className + "Service;\n");
						serviceImplOutputWriter.write("import "+ targetSpace + "." + className + "Mapper;\n");
						serviceImplOutputWriter.write("import org.springframework.stereotype.Service;\n");
						serviceImplOutputWriter.write("import org.springframework.transaction.annotation.Transactional;\n");
						serviceImplOutputWriter.write("import java.util.*;\n\n");
						serviceImplOutputWriter.write("import "+ nameSpace +"."+className+";\n\n");
						
						serviceImplOutputWriter.write("/**\n");
						serviceImplOutputWriter.write(" *<pre>\n");
						serviceImplOutputWriter.write(" * <b>Company</b> "+ companyName +" \n");
						//serviceImplOutputWriter.write(" * <b>Date</b> "+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) +"\n");
						serviceImplOutputWriter.write(" * <b>Author</b> " + file_author +"\n");
						serviceImplOutputWriter.write(" * <b>Project</b> "+ projectName +"\n");
						serviceImplOutputWriter.write(" * <b>Description</b> 用于"+className+"类的业务操作类 I"+className+"Service的实现类 \n");
						serviceImplOutputWriter.write(" * <b>Version</b> 1.0\n");
						serviceImplOutputWriter.write(" *</pre>\n");
						serviceImplOutputWriter.write(" */\n");
						
						serviceImplOutputWriter.write("@SuppressWarnings(\"serial\")\n");
						serviceImplOutputWriter.write("@Service(\""+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"Service\")\n");
						//serviceImplOutputWriter.write("@Service(\""+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"ServiceTarget\")\n");
						serviceImplOutputWriter.write("@Transactional\n");
						serviceImplOutputWriter.write("public class "+className+"ServiceImpl implements I"+className+"Service{\n");
						serviceImplOutputWriter.write("\t@Resource \n");
						serviceImplOutputWriter.write("\tprivate "+className+"Mapper "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"Mapper;\n");
						
						//创建当前对象的Mapper头部
						createMapperHead(outputWriter);
						outputWriter.write("<mapper namespace=\""+targetSpace+"."+className+"Mapper\">\n");
						//配置缓存数据。需要在LIB中加入mybatis-ehcache、ehcache-core这两个jar包
						outputWriter.write("\t<!-- <cache type=\"org.mybatis.caches.ehcache.EhcacheCache\" eviction=\"FIFO\" flushInterval=\"60000\" size=\"512\" readOnly=\"true\"/> -->\n");
						//创建一个resultMap方便当前对象的映射
						StringBuilder resultMap = new StringBuilder("\t<resultMap id=\""+className+"Result\" type=\"" + className + "\">\n");
						//创建一个插入对象
						StringBuilder insertObject_Header = new StringBuilder("\t<!-- 插入对象"+ className +" -->\n");
						StringBuilder insertObjectSelective_Header = new StringBuilder("\t<!-- 插入对象"+ className +"选择性插入数据 -->\n");
						StringBuilder insertObject_Fileds = new StringBuilder();
						StringBuilder insertObjectSelective_Fileds = new StringBuilder();
						StringBuilder insertObject_Values = new StringBuilder();
						StringBuilder insertObjectSelective_Values = new StringBuilder();
						StringBuilder insertObject_Footer = new StringBuilder(")\n\t</insert>\n");
						StringBuilder insertObjectSelective_Footer = new StringBuilder("\t\t</trim>\n\t</insert>\n");
						//创建一个删除的语句
						StringBuilder deleteObjectById = new StringBuilder("\t<!-- 通过指定的ID删除对象"+ className +" -->\n");
						//创建一个修改对象的语句
						StringBuilder updateObject = new StringBuilder("\t<!-- 更新对象"+ className +" -->\n");
						StringBuilder updateObjectWhere = new StringBuilder();
						//创建一个查询根据当前主键ID获取对象的语句
						StringBuilder queryForObject = new StringBuilder();
						//获取所有的集合
						StringBuilder queryForList = new StringBuilder();
						StringBuilder queryForList_Fileds = new StringBuilder();
						//获取所有的集合并且带分页
						StringBuilder queryForLists = new StringBuilder();
						//判断条件
						StringBuilder commonQueryForWhere = new StringBuilder("\t<!-- 所有的条件判断 -->\n\t<!-- \n");
						//判断当前对象是不是存在字段
						if(null!=fields && fields.length>0){
							//开始循环创建对象
							for (Field field : fields) {
								//设置这个字段的访问级别
								field.setAccessible(true);
								//获取当前字段的名称
								String field_name = field.getName();
								//由于当前的使用的是JPA的方式生成的Entity对象那么在获取当前字段对应数据库的字段时就需要用到方法了
								Method field_method = Class.forName(nameSpace + "." + className, true, ClassLoader.getSystemClassLoader()).getMethod("get" + field_name.substring(0, 1).toUpperCase() + field_name.substring(1), new Class[] {});
								//字段上的注解数组
								Annotation[] field_annotations = field_method.getAnnotations();
								//获取当前的字段的类型的类的名称
								String field_typeName = field.getType().getName();
								//获取JavaType。由于有的时候使用的是INT类型的字段，那么我们就要将当前的对象转换成对象类型去操作
								//field_typeName = getJavaTypeByTypeName(field_typeName);					暂时未实现
								boolean isIdField = false,isGeneratedField = false;
								isIdAndGeneratedField(field_annotations,isIdField,isGeneratedField);
								for (Annotation annotation : field_annotations) {
									//判断是不是Id类型的字段。
									if(javax.persistence.Id.class == annotation.annotationType()){
										isIdField = true;
										continue;
									}
									//判断是不是自动标志的字段。
									if(javax.persistence.GeneratedValue.class == annotation.annotationType()){
										isGeneratedField = true;
										continue;
									}else if(javax.persistence.Temporal.class == annotation.annotationType()){
										continue;
									}
									if(isIdField){
										if(annotation.annotationType() == javax.persistence.Column.class){
											//获取当前列。
											Column column = (Column) annotation;
											//将主键添加到当前的resultMap中
											resultMap.append("\t\t<id property=\"" + field_name + "\" column=\"" + column.name() + "\" javaType=\""+ field_typeName +"\"/>\n");
											//添加插入数据的语句
											if(isGeneratedField){
												insertObject_Header.append("\t<insert id=\"save"+className+"\" parameterType=\""+ className +"\" useGeneratedKeys=\"true\" keyProperty=\""+ field_name +"\" flushCache=\"true\">\n");
											}else{
												insertObject_Header.append("\t<insert id=\"save"+className+"\" parameterType=\""+ className +"\" flushCache=\"true\">\n");
											}
											insertObject_Header.append("\t\tinsert into "+tableName+" (");
											
											if(isGeneratedField){
												insertObjectSelective_Header.append("\t<insert id=\"save"+className+"Selective\" parameterType=\""+ className +"\" useGeneratedKeys=\"true\" keyProperty=\""+ field_name +"\" flushCache=\"true\">\n");
											}else{
												insertObjectSelective_Header.append("\t<insert id=\"save"+className+"Selective\" parameterType=\""+ className +"\" flushCache=\"true\">\n");
											}
											insertObjectSelective_Header.append("\t\tinsert into "+tableName+"\n\t\t<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">");
											
											insertObject_Values.append(") \n\t\tvalues(");
											insertObjectSelective_Values.append("\t\t</trim>\n\t\t<trim prefix=\"values (\" suffix=\")\" suffixOverrides=\",\">");
											insertObject_Fileds.append(column.name()+",");
											insertObject_Values.append("#{"+ field_name + "},");
											insertObjectSelective_Fileds.append("\n\t\t\t"+ column.name() + ",\n");
											insertObjectSelective_Values.append("\n\t\t\t#{"+field_name+"},\n");
											//删除对象的语句
											deleteObjectById.append("\t<delete id=\"delete"+className+"By"+field_name+"\" parameterType=\""+field_typeName+"\" flushCache=\"true\">\n");
											deleteObjectById.append("\t\tdelete from "+tableName+" where "+column.name()+"= #{"+field_name+"}\n");
											deleteObjectById.append("\t</delete>\n");
											//修改数据
											updateObject.append("\t<update id=\"update"+className+"\" parameterType=\""+className+"\" flushCache=\"true\">\n");
											updateObject.append("\t\tupdate "+tableName+" set \n");
											updateObjectWhere.append("\t\t\t" + column.name()+" = #{"+field_name+"}\n\t\twhere "+column.name()+" = #{"+field_name+"}\n");
											//根据当前主键的Id获取对象
											queryForObject.append("\t<!-- 根据当前的" + field_name + "获取对象"+ className + " -->\n");
											queryForObject.append("\t<select id=\"query" + className + "\" resultMap=\"" + className + "Result\"  parameterType=\"" + field_typeName + "\">\n");
											queryForObject.append("\t\tselect * from " + tableName + " where " + column.name() + "= #{" + field_name + "}\n");
											queryForObject.append("\t</select>\n");
											//获取所有的数据
											queryForList.append("\t<!-- 获取当前的" + tableName + "表中所有的"+ className + "对象 -->\n");
											queryForList.append("\t<select id=\"query"+className+"List\" resultMap=\"" + className + "Result\"  parameterType=\"" + className + "\">\n");
											queryForList.append("\t\tselect * from " + tableName +" where 1 = 1 \n");
											
											//获取对象并且支持分页，需要参考注释编写代码
											queryForLists.append("\t<!-- 获取当前的" + tableName + "表中所有的"+ className + "对象，支持分页并支持自定义排序 -->\n");
											queryForLists.append("\t<select id=\"query"+className+"Lists\" resultMap=\"" + className + "Result\"  parameterType=\"java.util.Map\">\n");
											queryForLists.append("\t\tselect * from " + tableName +"\n");
											queryForLists.append("\t\t<choose>\n");
											queryForLists.append("\t\t\t<when test=\"null != orderName and '' != orderName\">\n");
											queryForLists.append("\t\t\t\torder by ${orderName}\n");
											queryForLists.append("\t\t\t</when>\n");
											queryForLists.append("\t\t\t<otherwise> order by "+ column.name() +" DESC</otherwise>\n");
											queryForLists.append("\t\t</choose>\n");
											queryForLists.append("\t</select>\n");
											
											//生成文件
											
											//保存对象
											ioutputWriter.write("\n\t/**\n");
											ioutputWriter.write("\t * 保存"+className+"对象\n");
											ioutputWriter.write("\t * @param "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"\n");
											ioutputWriter.write("\t */\n");
											ioutputWriter.write("\tpublic int save"+className+"("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception;\n\n");
											
											//保存对象并选择不添加空数据
											ioutputWriter.write("\t/**\n");
											ioutputWriter.write("\t * 保存"+className+"对象\n");
											ioutputWriter.write("\t * @param "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"\n");
											ioutputWriter.write("\t */\n");
											ioutputWriter.write("\tpublic int save"+className+"Selective("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception;\n\n");
											
											//根据Id删除当前对象
											ioutputWriter.write("\t/**\n");
											ioutputWriter.write("\t * 根据"+field_name+"删除"+className+"\n");
											ioutputWriter.write("\t * @param "+field_name+"\n");
											ioutputWriter.write("\t */\n");
											ioutputWriter.write("\tpublic void delete"+className+"By"+field_name+"("+field_typeName+" "+field_name+") throws Exception;\n\n");;
											
											//更新对象操作
											ioutputWriter.write("\t/**\n");
											ioutputWriter.write("\t * 更新对象"+className+"\n");
											ioutputWriter.write("\t * @param "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"\n");
											ioutputWriter.write("\t */\n");
											ioutputWriter.write("\tpublic int update"+className+"("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception;\n\n");
											
											//获取单个对象
											ioutputWriter.write("\t/**\n");
											ioutputWriter.write("\t * 根据"+field_name+"获取"+className+"\n");
											ioutputWriter.write("\t * @param "+field_name+"\n");
											ioutputWriter.write("\t * @return "+className+"\n");
											ioutputWriter.write("\t */\n");
											ioutputWriter.write("\tpublic "+className+" query"+className+"("+field_typeName+" "+field_name+") throws Exception;\n\n");
											
											//获取集合列表
											ioutputWriter.write("\t/**\n");
											ioutputWriter.write("\t * 根据对象获取所有的"+className+"集合\n");
											ioutputWriter.write("\t * @param "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"\n");
											ioutputWriter.write("\t * @return List<"+className+">\n");
											ioutputWriter.write("\t */\n");
											ioutputWriter.write("\tpublic List<"+className+"> query"+className+"List("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception;\n\n");
											
											//获取带分页的列表 需要使用PaginationQueryList
											ioutputWriter.write("\t/**\n");
											ioutputWriter.write("\t * 根据对象获取所有的"+className+"集合，并且支持分页使用PaginationQueryList对象\n");
											ioutputWriter.write("\t * @param Map<String,Object> map\n");
											ioutputWriter.write("\t * @param RowBounds rowBounds\n");
											ioutputWriter.write("\t * @return List<"+className+">\n");
											ioutputWriter.write("\t * <pre>\n");
											ioutputWriter.write("\t * Map&lt;String,Object&gt; map =new HashMap&lt;String,Object&gt;();\n");
											ioutputWriter.write("\t * map.put(\""+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"\", "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+");\n");
											ioutputWriter.write("\t * map.put(\"orderName\", orderName);\n");
											ioutputWriter.write("\t * RowBounds rowBounds = null;\n");
											ioutputWriter.write("\t * if(0 &lt; pageSize){\n");
											ioutputWriter.write("\t * 		rowBounds = new RowBounds(currentPage, pageSize, true);\n");
											ioutputWriter.write("\t * }\n");
											ioutputWriter.write("\t * List&lt;"+className+"&gt; list = "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"Mapper.queryForListWithOrderName(map,rowBounds);\n");
											ioutputWriter.write("\t * Page page = new Page(currentPage, (pageSize&lt;1?1:pageSize), list instanceof PaginationQueryList?((PaginationQueryList) list).getRowTotal():list.size());\n");
											ioutputWriter.write("\t * PageModel&lt;"+className+"&gt; pageModel = new PageModel&lt;"+className+"&gt;();\n");
											ioutputWriter.write("\t * pageModel.setData(list);\n");
											ioutputWriter.write("\t * pageModel.setPage(page);\n");
											ioutputWriter.write("\t * return pageModel;\n");
											ioutputWriter.write("\t * </pre>\n");
											ioutputWriter.write("\t */\n");
											ioutputWriter.write("\tpublic List<"+className+"> query"+className+"Lists(Map<String, Object> map, RowBounds rowBounds) throws Exception;\n\n");
											
											
											//业务逻辑
											//保存对象
											iserviceOutputWriter.write("\n\t/**\n");
											iserviceOutputWriter.write("\t * 保存"+className+"对象\n");
											iserviceOutputWriter.write("\t * @param "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"\n");
											iserviceOutputWriter.write("\t */\n");
											iserviceOutputWriter.write("\tpublic int save"+className+"("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception;\n\n");
											
											//保存对象
											iserviceOutputWriter.write("\t/**\n");
											iserviceOutputWriter.write("\t * 保存"+className+"对象并不插入空数据\n");
											iserviceOutputWriter.write("\t * @param "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"\n");
											iserviceOutputWriter.write("\t */\n");
											iserviceOutputWriter.write("\tpublic int save"+className+"Selective("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception;\n\n");
											
											//根据Id删除当前对象
											iserviceOutputWriter.write("\t/**\n");
											iserviceOutputWriter.write("\t * 根据"+field_name+"删除"+className+"\n");
											iserviceOutputWriter.write("\t * @param "+field_name+"\n");
											iserviceOutputWriter.write("\t */\n");
											iserviceOutputWriter.write("\tpublic void delete"+className+"By"+field_name+"("+field_typeName+" "+field_name+") throws Exception;\n\n");
											
											//更新对象操作
											iserviceOutputWriter.write("\t/**\n");
											iserviceOutputWriter.write("\t * 更新对象"+className+"\n");
											iserviceOutputWriter.write("\t * @param "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"\n");
											iserviceOutputWriter.write("\t */\n");
											iserviceOutputWriter.write("\tpublic int update"+className+"("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception;\n\n");
											
											//获取单个对象
											iserviceOutputWriter.write("\t/**\n");
											iserviceOutputWriter.write("\t * 根据"+field_name+"获取"+className+"\n");
											iserviceOutputWriter.write("\t * @param "+field_name+"\n");
											iserviceOutputWriter.write("\t * @return "+className+"\n");
											iserviceOutputWriter.write("\t */\n");
											iserviceOutputWriter.write("\tpublic "+className+" query"+className+"("+field_typeName+" "+field_name+") throws Exception;\n\n");
											
											//获取集合列表
											iserviceOutputWriter.write("\t/**\n");
											iserviceOutputWriter.write("\t * 根据对象获取所有的"+className+"集合\n");
											iserviceOutputWriter.write("\t * @param "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"\n");
											iserviceOutputWriter.write("\t * @return List<"+className+">\n");
											iserviceOutputWriter.write("\t */\n");
											iserviceOutputWriter.write("\tpublic List<"+className+"> query"+className+"List("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception;\n\n");
											
											
											//实现类的方法
											//保存对象
											serviceImplOutputWriter.write("\n\t/*\n");
											serviceImplOutputWriter.write("\t * (non-Javadoc)\n");
											serviceImplOutputWriter.write("\t * @see "+serviceSpace+".I"+className+"Service#save"+className+"("+className+")\n");
											serviceImplOutputWriter.write("\t */\n");
											serviceImplOutputWriter.write("\t@Transactional(readOnly=false,rollbackFor={Exception.class})\n");
											serviceImplOutputWriter.write("\tpublic int save"+className+"("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception{\n");
											serviceImplOutputWriter.write("\t\treturn "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"Mapper.save"+className+"("+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+");\n");
											serviceImplOutputWriter.write("\t}\n\n");
											
											//保存对象对象并不插入空数据
											serviceImplOutputWriter.write("\t/*\n");
											serviceImplOutputWriter.write("\t * (non-Javadoc)\n");
											serviceImplOutputWriter.write("\t * @see "+serviceSpace+".I"+className+"Service#save"+className+"Selective("+className+")\n");
											serviceImplOutputWriter.write("\t */\n");
											serviceImplOutputWriter.write("\t@Transactional(readOnly=false,rollbackFor={Exception.class})\n");
											serviceImplOutputWriter.write("\tpublic int save"+className+"Selective("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception{\n");
											serviceImplOutputWriter.write("\t\treturn "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"Mapper.save"+className+"Selective("+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+");\n");
											serviceImplOutputWriter.write("\t}\n\n");
											
											//根据Id删除当前对象
											serviceImplOutputWriter.write("\t/*\n");
											serviceImplOutputWriter.write("\t * (non-Javadoc)\n");
											serviceImplOutputWriter.write("\t * @see "+serviceSpace+".I"+className+"Service#delete"+className+"By"+field_name+"("+field_typeName+")\n");
											serviceImplOutputWriter.write("\t */\n");
											serviceImplOutputWriter.write("\t@Transactional(readOnly=false,rollbackFor={Exception.class})\n");
											serviceImplOutputWriter.write("\tpublic void delete"+className+"By"+field_name+"("+field_typeName+" "+field_name+") throws Exception{\n");
											serviceImplOutputWriter.write("\t\t"+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"Mapper.delete"+className+"By"+field_name+"("+field_name+");\n");
											serviceImplOutputWriter.write("\t}\n\n");
											
											//更新对象操作
											serviceImplOutputWriter.write("\t/*\n");
											serviceImplOutputWriter.write("\t * (non-Javadoc)\n");
											serviceImplOutputWriter.write("\t * @see "+serviceSpace+".I"+className+"Service#update"+className+"("+className+")\n");
											serviceImplOutputWriter.write("\t */\n");
											serviceImplOutputWriter.write("\t@Transactional(readOnly=false,rollbackFor={Exception.class})\n");
											serviceImplOutputWriter.write("\tpublic int update"+className+"("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception{\n");
											serviceImplOutputWriter.write("\t\treturn "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"Mapper.update"+className+"("+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+");\n");
											serviceImplOutputWriter.write("\t}\n\n");
											
											//获取单个对象
											serviceImplOutputWriter.write("\t/*\n");
											serviceImplOutputWriter.write("\t * (non-Javadoc)\n");
											serviceImplOutputWriter.write("\t * @see "+serviceSpace+".I"+className+"Service#query"+className+"("+field_typeName+")\n");
											serviceImplOutputWriter.write("\t */\n");
											serviceImplOutputWriter.write("\t@Transactional(readOnly=true,rollbackFor={Exception.class})\n");
											serviceImplOutputWriter.write("\tpublic "+className+" query"+className+"("+field_typeName+" "+field_name+") throws Exception{\n");
											serviceImplOutputWriter.write("\t\treturn "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"Mapper.query"+className+"("+field_name+");\n");
											serviceImplOutputWriter.write("\t}\n\n");
											
											//获取集合列表
											serviceImplOutputWriter.write("\t/*\n");
											serviceImplOutputWriter.write("\t * (non-Javadoc)\n");
											serviceImplOutputWriter.write("\t * @see "+serviceSpace+".I"+className+"Service#query"+className+"List("+className+")\n");
											serviceImplOutputWriter.write("\t */\n");
											serviceImplOutputWriter.write("\t@Transactional(readOnly=true,rollbackFor={Exception.class})\n");
											serviceImplOutputWriter.write("\tpublic List<"+className+"> query"+className+"List("+className+" "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+") throws Exception{\n");
											serviceImplOutputWriter.write("\t\treturn "+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"Mapper.query"+className+"List("+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+");\n");
											serviceImplOutputWriter.write("\t}\n\n");
											
										}
										isIdField = false;
										isGeneratedField = false;
									}else{
										if(annotation.annotationType() == javax.persistence.Column.class){
											Column column = (Column) annotation;
											if(column.nullable()){
												if(field_typeName.endsWith("String")){
													insertObjectSelective_Fileds.append("\t\t\t<if test=\"null != "+ field_name +" and '' != "+ field_name +" \">"+column.name()+",</if>\n");
													insertObjectSelective_Values.append("\t\t\t<if test=\"null != "+ field_name +" and '' != "+ field_name +" \">#{"+field_name+"},</if>\n");
												}else if(field_typeName.endsWith("Integer") || field_typeName.endsWith("Long") || field_typeName.endsWith("Double") || field_typeName.endsWith("Short") || field_typeName.endsWith("Float")){
													insertObjectSelective_Fileds.append("\t\t\t<if test=\"null != "+ field_name +" and "+ field_name +" > -1 \">"+column.name()+",</if>\n");
													insertObjectSelective_Values.append("\t\t\t<if test=\"null != "+ field_name +" and "+ field_name +" > -1 \">#{"+field_name+"},</if>\n");
												}else{
													insertObjectSelective_Fileds.append("\t\t\t<if test=\"null != "+ field_name +" \">"+column.name()+",</if>\n");
													insertObjectSelective_Values.append("\t\t\t<if test=\"null != "+ field_name +" \">#{"+field_name+"},</if>\n");
												}
											}else{
												insertObjectSelective_Fileds.append("\t\t\t"+column.name()+",\n");
												insertObjectSelective_Values.append("\t\t\t#{"+field_name+"},\n");
											}
											resultMap.append("\t\t<result property=\""+field_name+"\" column=\""+column.name()+"\" javaType=\""+ field_typeName +"\"/>\n");
											insertObject_Fileds.append(column.name()+",");
											insertObject_Values.append("#{"+ field_name + "},");
											
											//查询
											//updateObject.append("\t\t\t"+column.name()+" = #{"+field_name+"},\n");
											
//											if(field_typeName.endsWith("String")){
//												insertObjectSelective_Fileds.append("\n\t\t\t#{"+ field_name + ",jdbcType=CHAR},");
//											}else if(field_typeName.endsWith("Date")){
//												insertObjectSelective_Fileds.append("\n\t\t\t#{"+ field_name + ",jdbcType=DATE},");
//											}else if(field_typeName.endsWith("Short")){
//												insertObjectSelective_Fileds.append("\n\t\t\t#{"+ field_name + ",jdbcType=INTEGER},");
//											}else if(field_typeName.endsWith("Integer")){
//												insertObjectSelective_Fileds.append("\n\t\t\t#{"+ field_name + ",jdbcType=INTEGER},");
//											}else if(field_typeName.endsWith("Long")){
//												insertObjectSelective_Fileds.append("\n\t\t\t#{"+ field_name + ",jdbcType=BIGINT},");
//											}else if(field_typeName.endsWith("Float")){
//												insertObjectSelective_Fileds.append("\n\t\t\t#{"+ field_name + ",jdbcType=FLOAT},");
//											}else if(field_typeName.endsWith("Double")){
//												insertObjectSelective_Fileds.append("\n\t\t\t#{"+ field_name + ",jdbcType=DOUBLE},");
//											}
//											else{
//												insertObjectSelective_Fileds.append("\n\t\t\t#{"+ field_name + "},");
//											}
											
											//下面是公共的查询条件
											if(field_typeName.endsWith("String") || field_typeName.endsWith("Date") || field_typeName.endsWith("Integer") || field_typeName.endsWith("Long") || field_typeName.endsWith("Double") || field_typeName.endsWith("Short") || field_typeName.endsWith("Float")){
												if(field_typeName.endsWith("String")){
													updateObject.append("\t\t\t<if test=\"null != "+ field_name +" and '' != "+ field_name +" \">\n");
													updateObject.append("\t\t\t\t"+column.name()+" = #{"+field_name+"},\n");
													updateObject.append("\t\t\t</if>\n");
													
													queryForList_Fileds.append("\t\t<if test=\"null != "+ field_name +" and '' != "+ field_name +" \">\n");
													queryForList_Fileds.append("\t\t\tand "+column.name()+" = #{"+field_name+"}\n");
													queryForList_Fileds.append("\t\t</if>\n");
													
													commonQueryForWhere.append("\t\t<if test=\"null != "+ field_name +" and '' != "+ field_name +" \">\n");
													commonQueryForWhere.append("\t\t\t"+column.name()+" = #{"+field_name+"},\n");
													commonQueryForWhere.append("\t\t</if>\n");
												}else if(field_typeName.endsWith("Integer") || field_typeName.endsWith("Long") || field_typeName.endsWith("Double") || field_typeName.endsWith("Short") || field_typeName.endsWith("Float")){
													updateObject.append("\t\t\t<if test=\"null != "+ field_name +" and "+ field_name +" > -1 \">\n");
													updateObject.append("\t\t\t\t"+column.name()+" = #{"+field_name+"},\n");
													updateObject.append("\t\t\t</if>\n");
													
													queryForList_Fileds.append("\t\t<if test=\"null != "+ field_name +" and "+ field_name +" > -1 \">\n");
													queryForList_Fileds.append("\t\t\tand "+column.name()+" = #{"+field_name+"}\n");
													queryForList_Fileds.append("\t\t</if>\n");
													
													commonQueryForWhere.append("\t\t<if test=\"null != "+ field_name +" and "+ field_name +" > -1 \">\n");
													commonQueryForWhere.append("\t\t\t"+column.name()+" = #{"+field_name+"},\n");
													commonQueryForWhere.append("\t\t</if>\n");
												}else{
													updateObject.append("\t\t\t<if test=\"null != "+ field_name +"\">\n");
													updateObject.append("\t\t\t\t"+column.name()+" = #{"+field_name+"},\n");
													updateObject.append("\t\t\t</if>\n");
													
													queryForList_Fileds.append("\t\t<if test=\"null != "+ field_name +"\">\n");
													queryForList_Fileds.append("\t\t\tand "+column.name()+" = #{"+field_name+"}\n");
													queryForList_Fileds.append("\t\t</if>\n");
													
													commonQueryForWhere.append("\t\t<if test=\"null != "+ field_name +"\">\n");
													commonQueryForWhere.append("\t\t\t"+column.name()+" = #{"+field_name+"},\n");
													commonQueryForWhere.append("\t\t</if>\n");
												}
											}else{
												updateObject.append("\t\t\t<if test=\""+ field_name +" > -1 \">\n");
												updateObject.append("\t\t\t\t"+column.name()+" = #{"+field_name+"},\n");
												updateObject.append("\t\t\t</if>\n");
												
												queryForList_Fileds.append("\t\t<if test=\""+ field_name +" > -1 \">\n");
												queryForList_Fileds.append("\t\t\tand "+column.name()+" = #{"+field_name+"}\n");
												queryForList_Fileds.append("\t\t</if>\n");
												
												commonQueryForWhere.append("\t\t<if test=\""+ field_name +" > -1 \">\n");
												commonQueryForWhere.append("\t\t\t"+column.name()+" = #{"+field_name+"},\n");
												commonQueryForWhere.append("\t\t</if>\n");
											}
										}
									}
								}
							}
						}
						//循环结束
						//创建
						outputWriter.write(resultMap.append("\t</resultMap>\n").toString());
						//增加对象
						outputWriter.write(insertObject_Header.append(insertObject_Fileds.substring(0, insertObject_Fileds.length()-1)).append(insertObject_Values.substring(0, insertObject_Values.length()-1)).append(insertObject_Footer).toString());
						//增加对象
						outputWriter.write(insertObjectSelective_Header.append(insertObjectSelective_Fileds).append(insertObjectSelective_Values).append(insertObjectSelective_Footer).toString());
						//删除对象
						outputWriter.write(deleteObjectById.toString());
						//修改对象
						//outputWriter.write(updateObject.delete(updateObject.length()-2, updateObject.length()-1).append(updateObjectWhere).append("\t</update>\n").toString());
						outputWriter.write(updateObject.append(updateObjectWhere).append("\t</update>\n").toString());
						//查询对象
						outputWriter.write(queryForObject.toString());
						//查询集合对象
						outputWriter.write(queryForList.append(queryForList_Fileds).append("\t</select>\n").toString());
						//查询集合对象并支持分页以及自定义排序
						outputWriter.write(queryForLists.toString());
						//判断的条件
						outputWriter.write(commonQueryForWhere.append("\t-->\n").toString());
						outputWriter.write("</mapper>");
						//写入文件中
						ioutputWriter.write("}");
						iserviceOutputWriter.write("}");
						serviceImplOutputWriter.write("}");
						//将数据刷新到文件中
						outputWriter.flush();
						ioutputWriter.flush();
						iserviceOutputWriter.flush();
						serviceImplOutputWriter.flush();
						outputWriter.close();
						ioutputWriter.close();
						iserviceOutputWriter.close();
						serviceImplOutputWriter.close();
						System.out.println("<typeAlias alias=\""+className+"\" type=\""+nameSpace+"."+className+"\"/>");
						//System.out.println("\n\t<!-- 定义“"+className+"ServiceImpl” 的配置 -->");
						//System.out.println("\t<bean id=\""+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"Service\" class=\""+serviceImplSpace+"."+className+"ServiceImpl\" autowire=\"byName\" />");
//						System.out.println("\t<bean id=\""+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"ServiceTarget\" class=\""+serviceImplSpace+"."+className+"ServiceImpl\" autowire=\"byName\" />");
//						System.out.println("\t<bean id=\""+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"Service\" class=\"org.springframework.aop.framework.ProxyFactoryBean\" autowire=\"byName\" >");
//						System.out.println("\t\t<property name=\"target\">");
//						System.out.println("\t\t\t<ref local=\""+className.substring(0,1).toLowerCase()+className.substring(1,className.length())+"ServiceTarget\" />");
//						System.out.println("\t\t</property>");
//						System.out.println("\t\t<property name=\"interceptorNames\">");
//						System.out.println("\t\t\t<list>");
//						System.out.println("\t\t\t\t<value>methodCachePointCut</value>");
//						System.out.println("\t\t\t\t<value>methodCachePointCutAdvice</value>");
//						System.out.println("\t\t\t</list>");
//						System.out.println("\t\t</property>");
//						System.out.println("\t</bean>");
					}catch (Exception e) {
						logger.error(e.getMessage());
						e.printStackTrace();
					}
				}
			}
		}
		//判断文件
		//System.out.println(file);
	}
	
	/**
	 * 创建Mapper的头部
	 * @param outputWriter				输出的文件的存放位置
	 * @throws IOException
	 */
	public void createMapperHead(OutputStreamWriter outputWriter) throws IOException{
		try {
			outputWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
			outputWriter.write("<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">\n");
			outputWriter.flush();
		} catch (UnsupportedEncodingException e) {
			logger.info(e.getMessage());
			throw e;
		} catch (FileNotFoundException e) {
			logger.info(e.getMessage());
			throw e;
		} catch (IOException e) {
			logger.info(e.getMessage());
			throw e;
		}
	}
	
	/**
	 * 获取所有的字段，传入参数类名称需要完整的名称例如String类就要写成java.lang.String
	 * @param className									传入的类的名称
	 * @throws ClassNotFoundException					抛出类没有找到的错误
	 */
	public Field[] getFieldsOfClass(String className) throws ClassNotFoundException{
		Field[] fields = null;
		try {
			fields = Class.forName(className, true, ClassLoader.getSystemClassLoader()).getDeclaredFields();
		} catch (SecurityException e) {
			logger.info(e.getMessage());
			throw e;
		} catch (ClassNotFoundException e) {
			logger.info(e.getMessage());
			throw e;
		}
		return fields;
	}
	
	/**
	 * 获取所有的注解，传入参数类名称需要完整的名称例如String类就要写成java.lang.String
	 * @param className
	 * @throws ClassNotFoundException
	 */
	public Annotation[] getAnnotationsOfClass(String className) throws ClassNotFoundException {
		Annotation[] annotations = null;
		try {
			annotations = Class.forName(className, true, ClassLoader.getSystemClassLoader()).getAnnotations();
		} catch (ClassNotFoundException e) {
			logger.info(e.getMessage());
			throw e;
		}
		return annotations;
	}
	
	/**
	 * 根据注解获取当前的Entity类中对应的数据库中的表的名称
	 * @param annotations
	 * @return
	 */
	public String getTableNameOfClassByAnnotations(Annotation[] annotations){
		String tableName = "";
		for (Annotation annotation : annotations) {
			if(javax.persistence.Table.class == annotation.annotationType()){
				Table table = (Table) annotation;
				if(1 < table.catalog().length()){
					tableName = table.catalog() + "." + table.name();
				}else{
					tableName = table.name();
				}
			}
		}
		return tableName;
	}
	
	public void delFolder(String folderPath) {
		try {
			delAllFile(folderPath); // 删除完里面所有内容
			String filePath = folderPath;
			filePath = filePath.toString();
			java.io.File myFilePath = new java.io.File(filePath);
			myFilePath.delete(); // 删除空文件夹
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public boolean delAllFile(String path) {
		boolean flag = false;
		File file = new File(path);
		if (!file.exists()) {
			return flag;
		}
		if (!file.isDirectory()) {
			return flag;
		}
		String[] tempList = file.list();
		File temp = null;
		for (int i = 0; i < tempList.length; i++) {
			if (path.endsWith(File.separator)) {
				temp = new File(path + tempList[i]);
			} else {
				temp = new File(path + File.separator + tempList[i]);
			}
			if (temp.isFile()) {
				temp.delete();
			}
			if (temp.isDirectory()) {
				delAllFile(path + "/" + tempList[i]);// 先删除文件夹里面的文件
				delFolder(path + "/" + tempList[i]);// 再删除空文件夹
				flag = true;
			}
		}
		return flag;
	}
	
	private void isIdAndGeneratedField(Annotation[] annotations,boolean isIdField,boolean isGeneratedField){
		for (Annotation annotation : annotations) {
			if(javax.persistence.Id.class == annotation.annotationType()){
				isIdField = true;
				continue;
			}
			//判断是不是自动标志的字段。
			if(javax.persistence.GeneratedValue.class == annotation.annotationType()){
				isGeneratedField = true;
				continue;
			}
		}
	}
}